/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package com.headerfooter.songhang.library.component;

import ohos.agp.components.BaseItemProvider;
import ohos.agp.components.Component;

/**
 * 自定义瀑布流布局管理器父类
 */
public class SpanLayoutManager {
    /**
     * SpanLayout对象
     */
    protected SpanLayout mSpanLayout;

    /**
     * 宽度大小
     */
    protected int mWidthSize;

    /**
     * 宽度模式
     */
    protected int mWidthMode;

    /**
     * 高度大小
     */
    protected int mHeightSize;

    /**
     * 高度模式
     */
    protected int mHeightMode;

    /**
     * Recycler对象
     */
    protected Recycler mRecycler;

    /**
     * BaseItemProvider对象
     */
    protected BaseItemProvider mProvider;

    Span[] mSpans;
    int mSpanNum;

    /**
     * 构造方法
     *
     * @param spanNum 列数
     */
    public SpanLayoutManager(int spanNum) {
        mSpanNum = spanNum;
    }

    /**
     * 设置Recycler
     *
     * @param recycler Recycler对象
     */
    public void setRecycler(Recycler recycler) {
        mRecycler = recycler;
    }

    /**
     * 设置provider
     *
     * @param provider BaseItemProvider对象
     */
    public void setProvider(BaseItemProvider provider) {
        mProvider = provider;
    }

    /**
     * 设置SpanLayout
     *
     * @param spanLayout SpanLayout对象
     */
    public void setSpanLayout(SpanLayout spanLayout) {
        mSpanLayout = spanLayout;
        mWidthSize = mSpanLayout.getEstimatedWidth();
        mHeightSize = mSpanLayout.getEstimatedHeight();
    }

    /**
     * 估算大小
     *
     * @param widthEstimatedConfig 宽度配置
     * @param heightEstimatedConfig 高度配置
     */
    public void setEstimateSize(int widthEstimatedConfig, int heightEstimatedConfig) {
        mWidthSize = Component.EstimateSpec.getSize(widthEstimatedConfig);
        mHeightSize = Component.EstimateSpec.getSize(heightEstimatedConfig);
    }

    /**
     * 设置方向
     * @param orientation 方向标识
     */
    public void setOrientation(int orientation) {
    }

    /**
     * 填充布局
     *
     * @param left 左边
     * @param top 上边
     * @param right 右边
     * @param bottom 下边
     * @param direction 方向
     * @return boolean
     */
    public boolean fill(double left, double top, double right, double bottom, int direction) {
        return false;
    }

    static class Span {
        int index;

        int left;
        int top;
        int right;
        int bottom;

        int startLine;
        int endLine;

        @Override
        public String toString() {
            return "Span{" +
                    "index=" + index +
                    ", left=" + left +
                    ", top=" + top +
                    ", right=" + right +
                    ", bottom=" + bottom +
                    ", startLine=" + startLine +
                    ", endLine=" + endLine +
                    '}';
        }
    }

}
